home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 138
/
Volume 138 Aug 19 2011 - Damaged.iso
/
Games
/
hopes_babysitting_maze.swf
/
scripts
/
__Packages
/
Classes
/
bsmPlayer.as
< prev
Wrap
Text File
|
2011-08-19
|
9KB
|
302 lines
class Classes.bsmPlayer extends Classes.bsmEntity
{
var INVINCIBLE_TIME = 3;
var SLOW_TIME_EASY = 3;
var SLOW_TIME_HARD = 5;
var speed = 90;
var SCENTERX = 287.5;
var SCENTERY = 200;
function bsmPlayer(t_data, t_levelPath)
{
super();
this.assetID = t_data.assetID;
this.x = t_data.x;
this.y = t_data.y;
this.pushedBy = null;
this.levelPath = t_levelPath;
}
function spawn(t_path, t_depth)
{
this.path = t_path;
this.mc = t_path.attachMovie(this.assetID,this.assetID + t_depth,t_depth);
this.mc.stop();
this.placeAt(this.x,this.y);
this.hdOffsetPoint = {x:0,y:0};
this.path.hd.localToGlobal(this.hdOffsetPoint);
this.pushedBy = null;
this.baseWidth = 25;
this.baseHeight = 30;
this.hdWidth = 20;
this.hdHeight = 20;
this.render();
}
function hit(t_enemy)
{
this.push(t_enemy);
}
function push(t_enemy)
{
var _loc4_ = this.calculateFacingHD(this,t_enemy.mc);
if(_loc4_.collision)
{
this.xMove = 0;
this.yMove = 0;
}
var _loc3_ = this.calculateFacingHD(t_enemy,this.mc);
if(_loc3_.collision)
{
if(t_enemy.type == "perfume")
{
if(t_enemy.ignoreTimer <= 0 && t_enemy.sprayTimer <= 3)
{
t_enemy.sprayPerfume();
t_enemy.turnAround();
}
}
this.pushedBy = t_enemy;
if(_loc3_.dir == "left")
{
this.xMove += t_enemy.xMove;
}
else if(_loc3_.dir == "right")
{
this.xMove += t_enemy.xMove;
}
else if(_loc3_.dir == "up")
{
this.yMove += t_enemy.yMove;
}
else if(_loc3_.dir == "down")
{
this.yMove += t_enemy.yMove;
}
}
}
function update(t_elapsed)
{
var _loc5_ = this.xMove;
var _loc6_ = this.yMove;
this.xMove = 0;
this.yMove = 0;
if(t_elapsed > 0.04)
{
t_elapsed = 0.04;
}
if(!this.hidden)
{
var _loc2_ = this.speed * t_elapsed;
if(this.slowTimer > 0)
{
_loc2_ /= 3;
this.slowTimer -= t_elapsed;
if(this.slowTimer <= 0)
{
this.mc.cloud.gotoAndStop("off");
}
}
if(Key.isDown(37))
{
this.xMove = - _loc2_;
this.mc.gotoAndStop("left");
}
else if(Key.isDown(38))
{
this.yMove = - _loc2_;
this.mc.gotoAndStop("up");
}
else if(Key.isDown(39))
{
this.xMove = _loc2_;
this.mc.gotoAndStop("right");
}
else if(Key.isDown(40))
{
this.yMove = _loc2_;
this.mc.gotoAndStop("down");
}
else if(_loc5_ != 0 || _loc6_ != 0)
{
var _loc3_ = "standUp";
if(_loc6_ > 0)
{
_loc3_ = "standDown";
}
else if(_loc5_ > 0)
{
_loc3_ = "standRight";
}
else if(_loc5_ < 0)
{
_loc3_ = "standLeft";
}
this.mc.gotoAndStop(_loc3_);
}
if(this.invincibleTimer > 0)
{
this.invincibleTimer -= t_elapsed;
}
}
}
function move()
{
if(this.xMove != 0 || this.yMove != 0)
{
var _loc3_ = this.calculateFacingHD(this,this.path.hd);
if(_loc3_.collision)
{
if(this.pushedBy != null)
{
this.pushedBy.turnAround();
this.pushedBy = null;
}
var _loc4_ = 0;
var _loc5_ = 0;
var _loc2_ = _loc3_.points.length;
while(true)
{
_loc2_;
if(!_loc2_--)
{
break;
}
if(_loc3_.points[_loc2_].collide)
{
if(_loc3_.points[_loc2_].point == "cr" || _loc3_.points[_loc2_].point == "cl" || _loc3_.points[_loc2_].point == "ct" || _loc3_.points[_loc2_].point == "cb")
{
_loc5_ = 0;
_loc4_ = 0;
_loc2_ = 0;
}
else if(_loc3_.points[_loc2_].point == "tl")
{
if(this.xMove < 0)
{
_loc4_ = Math.abs(this.xMove);
}
else if(this.yMove < 0)
{
_loc5_ = Math.abs(this.yMove);
}
}
else if(_loc3_.points[_loc2_].point == "tr")
{
if(this.xMove > 0)
{
_loc4_ = this.xMove;
}
else if(this.yMove < 0)
{
_loc5_ = this.yMove;
}
}
else if(_loc3_.points[_loc2_].point == "br")
{
if(this.xMove > 0)
{
_loc4_ = - this.xMove;
}
else if(this.yMove > 0)
{
_loc5_ = - this.yMove;
}
}
else if(_loc3_.points[_loc2_].point == "bl")
{
if(this.xMove < 0)
{
_loc4_ = this.xMove;
}
else if(this.yMove > 0)
{
_loc5_ = this.yMove;
}
}
}
}
this.x += _loc5_;
this.y += _loc4_;
}
else
{
this.x += this.xMove;
this.y += this.yMove;
}
}
}
function hide()
{
this.slowTimer = 0;
this.mc.cloud.gotoAndStop("off");
super.hide();
}
function calculateFacingHD(t_entity, t_mc)
{
var _loc4_ = {tl:false,tr:false,bl:false,br:false,cb:false,cl:false,cr:false,ct:false};
var _loc11_ = undefined;
if(t_entity.xMove < 0)
{
_loc11_ = "left";
_loc4_.tl = true;
_loc4_.cl = true;
_loc4_.bl = true;
}
else if(t_entity.xMove > 0)
{
_loc11_ = "right";
_loc4_.tr = true;
_loc4_.cr = true;
_loc4_.br = true;
}
if(t_entity.yMove < 0)
{
_loc11_ = "up";
_loc4_.tl = true;
_loc4_.tr = true;
_loc4_.ct = true;
}
else if(t_entity.yMove > 0)
{
_loc11_ = "down";
_loc4_.bl = true;
_loc4_.br = true;
_loc4_.cb = true;
}
var _loc7_ = t_entity.x + t_entity.xMove;
var _loc6_ = t_entity.y + t_entity.yMove;
var _loc8_ = undefined;
var _loc10_ = undefined;
var _loc13_ = 2;
if(_loc11_ == "up" || _loc11_ == "down")
{
_loc8_ = t_entity.hdWidth / _loc13_;
_loc10_ = t_entity.hdHeight / _loc13_;
}
else
{
_loc8_ = t_entity.hdHeight / _loc13_;
_loc10_ = t_entity.hdWidth / _loc13_;
}
var _loc9_ = false;
var _loc3_ = [{point:"tl",x:_loc7_ - _loc8_,y:_loc6_ - _loc10_},{point:"tr",x:_loc7_ + _loc8_,y:_loc6_ - _loc10_},{point:"bl",x:_loc7_ - _loc8_,y:_loc6_ + _loc10_},{point:"br",x:_loc7_ + _loc8_,y:_loc6_ + _loc10_},{point:"cr",x:_loc7_ + _loc8_ + 2,y:_loc6_},{point:"cb",x:_loc7_,y:_loc6_ + _loc10_ + 2},{point:"cl",x:_loc7_ - _loc8_ - 2,y:_loc6_},{point:"ct",x:_loc7_,y:_loc6_ - _loc10_ - 2}];
var _loc2_ = _loc3_.length;
while(true)
{
_loc2_;
if(!_loc2_--)
{
break;
}
_loc3_[_loc2_].collide = false;
if(_loc4_[_loc3_[_loc2_].point])
{
_loc3_[_loc2_].collide = t_mc.hitTest(_loc3_[_loc2_].x + this.hdOffsetPoint.x,_loc3_[_loc2_].y + this.hdOffsetPoint.y,true);
if(_loc3_[_loc2_].collide)
{
_loc9_ = true;
}
}
}
return {collision:_loc9_,dir:_loc11_,points:_loc3_};
}
}